package com.ocm.mq.mq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author hqy
 * @Date 23/01/2022
 * @Description 延迟*订单主动解锁库存
 */
@Component
public class OrderDelayMq {

	@Bean
	public Queue orderDelayQueue(){
		Map<String,Object> args = new HashMap<>(3);
		args.put("x-dead-letter-exchange","order-event-exchange");
		args.put("x-dead-letter-routing-key","order.release.order");
		args.put("x-message-ttl",60000);
		return new Queue("order.delay.queue", true, false, false,args);
	}
	@Bean
	public Queue orderReleaseQueue(){
		return new Queue("order.release.order.queue", true, false, false);
	}

	@Bean
	public Binding orderCreateOrderBinding(){
		return new Binding(

			"order.delay.queue",
			Binding.DestinationType.QUEUE,
			"order-event-exchange",
			"order.create.order",
			null
		);
	}

	/**
	 * 库存解锁队列 用于主动解锁库存
	 * @return
	 */
	@Bean
	public Binding orderStockBinding(){
		return new Binding(
			"stock.release.stock.queue",
			Binding.DestinationType.QUEUE,
			"order-event-exchange",
			"order.release.other",
			null
		);
	}

	@Bean
	public Binding orderReleaseOrderBinding(){
		return new Binding(
			"order.release.order.queue",
			Binding.DestinationType.QUEUE,
			"order-event-exchange",
			"order.release.order",
			null
		);
	}

	/**
	 * 订单支付队列
	 * @return
	 */
	@Bean
	public Queue orderPayQueue(){
		return new Queue("order.pay.queue", true, false, false);
	}

	/**
	 * 订单支付成功异步通知
	 * @return
	 */
	@Bean
	public Binding orderPayBinding(){
		return new Binding(
			"order.pay.queue",
			Binding.DestinationType.QUEUE,
			"order-event-exchange",
			"order.pay.order",
			null
		);
	}




}
